<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var solveEquation = function (equation) {
      let a = 0, b = 0, c = 0, sign = 1, left = 1, hasC = false;
      for (let z of equation) {
        switch (z) {
          case 'x':
            a += hasC ? sign * left * c : sign * left, c = 0, hasC = false;
            break;
          case '+':
            b += sign * left * c, c = 0, sign = 1, hasC = false;
            break;
          case '-':
            b += sign * left * c, c = 0, sign = -1, hasC = false;
            break;
          case '=':
            b += sign * left * c, c = 0, sign = 1, left = -1, hasC = false;
            break;
          default:
            c = c * 10 + (z - '0'), hasC = true;
            break;
        }
      }
      b += sign * left * c;
      return a === 0 ? b === 0 ? "Infinite solutions" : "No solution" : "x=" + -b / a;
    };
    console.log(solveEquation("x+5-3+x=6+x-2"))
  </script>
</body>

</html>